<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<title>消息列表</title>

		<meta name="viewport" content="initial-scale=1, maximum-scale=1">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<!-- 引入css文件 -->
		<link rel="stylesheet" href="../css/sm.min.css">
		<link rel="stylesheet" href="../css/sm-extend.min.css">
		<link rel="stylesheet" href="../css/iconfont.css">
		<style type="text/css">
			#index {
				margin-top: 0.4rem;
			}
			.infinite-scroll-preloader {
				margin-top: -20px;
			}
			/* 卡片内容加边距 */
			.my-cont{
				padding:.2rem .99rem;
				text-align:center
				
			}
			/* 背景色白色 */
			.page, .page-group{
				background-color: white;
			}
			/* 去掉卡片边距 */
			.card{
				/* margin: 0; */
			}
			/* 用户字体 */
			.list-block .my-user{
				font-size :0.6rem;
				color:rgb(150,150,150);
			}
			/* 头像圆角 */
			.my-photo img{
				border-radius: 1rem;
			}
			/*商品*/
			.commodity-title{
				font-weight: bold;
				font-size: medium;
			}
			.commodity-price{
				font-weight: bold;
				color: red;
				padding-right: 5rem;
			}
			/* 用户 */
			.user-name{
				font-size :0.75rem;
				font-weight: bold;
			}
			.message{
				font-size :0.6rem;
				color: grey;
			}
			/* 跳转连接颜色 */
			a{
				color: inherit;
			}
			a:active{
				color: inherit;
			}
			
			/* 卡片主内容左右边距 */
			.my-data{
				padding-right: 7rem;
			}
		</style>
	</head>
	<body>
		<!-- page 容器 -->
		<div class="page" id="app">
			<!-- 标题栏 -->
			<header class="bar bar-nav" style="background-color: yellow;">
				<h1 class="title" style="color: #000000;">消息</h1>
			</header>
			
			<!-- 工具栏 -->
			<nav class="bar bar-tab" style="background-color: yellow;">
				<a class="tab-item external " href="market-index.html">
					<!-- <span class="icon icon-home"></span> -->
					<span class="icon iconfont icon-chengshi"></span>
					<span class="tab-label">首页</span>
				</a>
				<a class="tab-item external" href="market-postgoods.html">
					<span class="icon iconfont icon-chuangzuo"></span>
					<span class="tab-label">发布商品</span>
				</a>
				<a class="tab-item external active" href="#">
					<span class="icon iconfont icon-message"></span>
					<span class="tab-label">消息</span>
				</a>
				<a class="tab-item external" href="market-mymainpage.html">
					<span class="icon iconfont icon-peoplelist"></span>
					<span class="tab-label">我的</span>
				</a>
			</nav>

			<!-- 页面内容 -->
			<div class="content">
				<!-- 主内容 -->
				<div class="list-block" >
					<div class="list-block media-list" v-for="message in allMessages">
						<ul>
						  <li>
							<a href="#" @click="goTalk(message)">
								<div class="item-content">
								  <div class="item-media">
									  <img :src="imgSrc(message.receiveUser.photo)" style='width: 2.2rem;height: 2.5rem;'>
								  </div>
								  <div class="item-inner">
									<div class="item-title-row">
									  <div class="user-name">{{message.receiveUser.nickname}}</div>
									</div>
									<div class="message">{{message.date}}</div>
								  </div>
								  <div class="" style="width: 36px;height: 47px;margin-right: 30px;">
								  	<img :src="imgSrc(message.commodity.picture)" style='height: 2.5rem;'>
								  </div>
								</div>
							</a>
						  </li>
						</ul>
					</div>
				</div>
			</div>
		</div>
		<script src='../js/jquery-3.2.1.min.js'></script>
		<script src='../js/sm.js'></script>
		<script src='../js/sm-extend.js'></script>
		<script src='../js/vue.js'></script>
		<script src='../js/axios.min.js'></script>
		<script src="../js/config.js"></script>
		
		<script>
			//VUE
			var app = new Vue({
				el:"#app",
				data:{
					loginUser:null,
					allMessages:[]
				},
				created() {
					//初始化加载登录用户信息
					this.initloginuser();
				},
				// 方法
				methods:{
					initloginuser: function() {
						axios.get(serviceIP+"/market/initloginuser",{
							headers:{"token":token,"refreshtoken":refreshtoken}
						}).then(result => {
							this.loginUser = result.data.data;
							//初始化加载所有消息
							this.initallmessages();
						});
					},
					initallmessages: function() {
						axios.get(serviceIP+"/market/initallmessages?loginUserId="+this.loginUser.id,{
							headers:{"token":token,"refreshtoken":refreshtoken}
						}).then(result => {
							this.allMessages = result.data.data;
						});
					},
		
					//跳到聊天页
					goTalk:function(message){
						window.location="market-talk.html?loginuserid="+this.loginUser.id
						+"&commodityid="+message.commodityId+"&userid="+message.receiveuserId
					},
					//图片映射
					imgSrc: function(src) {
						return src;
					},
					
				},
				
			});
		</script>
		
		<script>
			$.init();
		</script>
	</body>

</html>
